package com.sztest.jayjun.dialog;

import android.content.Context;
import android.widget.TextView;

import com.sztest.jayjun.MyApplication;
import com.sztest.jayjun.R;
import com.sztest.jayjun.constant.Constant;
import com.sztest.jayjun.dialog.BaseDialog.Base2Dialog;
import com.sztest.jayjun.mmkv.MMKVUtils;

import androidx.annotation.NonNull;

/*
 *  @项目名：  jayjun
 *  @包名：    com.sztest.jayjun.dialog
 *  @文件名:   HintDialog
 *  @创建者:   okmin
 *  @创建时间:  2022/6/29 10:17
 *  @描述：    TODO
 */
public class HintDialog extends Base2Dialog {
    private String mMsg;
    private boolean mIsDj;

    public HintDialog(@NonNull Context context) {
        super(context);
    }

    public HintDialog(@NonNull Context context, int themeResId) {
        super(context, themeResId);
    }

    @Override
    protected int getlayoutId() {
        return R.layout.hint_dialog;
    }
    TextView mTvContent;
    public void setMsg(String msg){
        mMsg = msg;
        if (mTvContent==null) {
            mTvContent= findViewById(R.id.tv_content);
        }
        mTvContent.setText(msg);
    }

    @Override
    public void show() {
        super.show();
        MyApplication.getInstance().OnOffLed(1);
        boolean select = MMKVUtils.getInstance().getBoolean(Constant.BUZZER);
        if (!select){
            MyApplication.getInstance().OnOffBuzzer(1);
            return;
        }
//        MyApplication.getInstance().mHandler.postDelayed(mRun,200);
    }

    Runnable mRun=new Runnable() {
        @Override
        public void run() {
            MyApplication.getInstance().OnOffBuzzer(0);
//            try {
//                Thread.sleep(100);
//            } catch (InterruptedException e) {
//                e.printStackTrace();
//            }
            MyApplication.getInstance().OnOffLed(0);
        }
    };

    @Override
    public void dismiss() {
        super.dismiss();
        MyApplication.getInstance().OnOffBuzzer(0);
        MyApplication.getInstance().OnOffLed(0);
        if (mIsDj){
            MyApplication.getInstance().OnOffMotor(0);
        }
    }

    public void setkey() {
        mIsDj=true;
        setMsg("电机异常,请检查.");
    }

    public void setfy() {
        mIsDj=false;
//        setMsg("负压不足,请检查气管是否脱落或是否贴紧皮肤.");
        setMsg("负压异常,请检查.");
    }
}
